package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.enums.BasicEnum;

import java.util.List;

/**
 * 护理项目Service实现类
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return projectVoPageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectVo nursingProjectVo) {
        Long count = nursingProjectMapper.getCountByName(nursingProjectVo.getName());
        if (count > 0) {
            throw new BaseException(BasicEnum.NURSING_INSERT_FAIL);
        }
        nursingProjectMapper.addNursingProject(nursingProjectVo);
    }

    @Override
    public NursingProjectVo getNursingProjectById(Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectMapper.getNursingProjectById(id);
        return nursingProjectVo;
    }

    @Override
    public void modifyNursingProject(NursingProjectVo nursingProjectVo) {
        nursingProjectMapper.modifyNursingProject(nursingProjectVo);
    }

    @Override
    public void modifyNursingProjectStatus(Long id, Integer status) {
        nursingProjectMapper.modifyNursingProjectStatus(id, status);
    }

    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public List<NursingProjectVo> getAllNursingProjects() {
        return nursingProjectMapper.getAllNursingProjects();
    }
}